import axios from 'axios';
import request from '@/axios';
const http = axios.create({
  baseURL: '/review',
});

export const getList = (current, size, params) => {
  return request({
    url: '/position/courseware/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    },
  });
};

export const getQuestionList = (current, size, params) => {
  return request({
    url: '/position/question/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    },
  });
};

export const getDetail = id => {
  return request({
    url: '/position/courseware/detail',
    method: 'get',
    params: {
      id,
    },
  });
};

export const getQuestionDetail = id => {
  return request({
    url: '/position/question/detail',
    method: 'get',
    params: {
      id,
    },
  });
};

export const remove = ids => {
  return request({
    url: '/position/courseware/remove',
    method: 'post',
    params: {
      ids,
    },
  });
};

export const removeQuestion = ids => {
  return request({
    url: '/position/question/remove',
    method: 'post',
    params: {
      ids,
    },
  });
};

export const add = row => {
  return request({
    url: '/position/courseware/submit',
    method: 'post',
    data: row,
  });
};

export const update = row => {
  return request({
    url: '/position/courseware/submit',
    method: 'post',
    data: row,
  });
};

export const updateQuestions = row => {
  return request({
    url: '/position/question/update',
    method: 'post',
    data: row,
  });
};

export const getKnowledgeInfo = url => {
  // return request({
  //   url: '/bladex/upload/' + url,
  //   method: 'get',
  // });
  return http.get(url);
};

export const buttonPermission = () => {
  return request({
    url: '/position/system/permission/button',
    method: 'get',
    params: {
      buttonCode: 'knowledge_courseware_download',
    },
  });
};

export const downloadFile = id => {
  return request({
    url: '/blade-resource/oss/endpoint/download-file-attach?attachId=' + id,
    method: 'get',
  });
};

export const pdfReview = fileId => {
  return axios({
    url: '/api/blade-resource/oss/endpoint/viewFile/pdf/' + fileId,
    method: 'get',
    responseType: 'blob',
  });
};
// http://39.98.80.21:9000/nebladex/upload/20240315/d2fee99fb07b6c679ca8734b8c0526bc.docx
// const local = axios.create({
//   baseURL: '/local',
// });
// export const localFile = path => local.get('/file?path=' + path);
export const localFile = attachId => {
  return request({
    url: '/blade-resource/oss/endpoint/viewUrl',
    method: 'get',
    params: {
      attachId,
    },
  });
};

export const start = coursewareId => {
  return request({
    url: '/position/coursewareStudyRecord/start',
    method: 'post',
    data: {
      coursewareId,
    },
  });
};

export const studyLog = (current, size) => {
  return request({
    url: '/position/studylog/list',
    method: 'get',
    params: {
      current,
      size,
    },
  });
};

export const serverTime = () => {
  return request({
    url: '/position/system/serverTime',
    method: 'get',
  });
};

export const studySubmit = data => {
  return request({
    url: '/position/studylog/submit',
    method: 'post',
    data,
  });
};

export const uploadQuestion = data => {
  return request({
    url: '/position/question/import-question',
    method: 'post',
    data,
  });
};
